<?php

namespace app\redis\supplier;

use yii\redis\ActiveRecord;

/**
 * Class Check
 * @package app\redis\supplier
 *
 * @property int $id
 * @property string $create_time
 * @property int $status
 * @property string $text
 * @property string $type
 * @property int $model_id
 */
class Check extends ActiveRecord
{
    public static function primaryKey()
    {
        return ['id'];
    }

    public function attributes()
    {
        return ['id', 'create_time', 'status', 'text', 'type', 'model_id'];
    }

    public static function getList()
    {
        return self::find()
            // 待审核状态
            ->where(['status' => 0])
            ->orderBy(['id' => SORT_DESC])
            ->asArray()
            ->all();
    }

    public static function getOne()
    {
        return self::find()
            // 待审核状态
            ->where(['status' => 0])
            ->orderBy(['id' => SORT_DESC])
            ->one();
    }

    // 创建
    public static function produce($type, $model_id, $text)
    {
        $model = new self();
        $model->create_time = date('Y-m-d H:i:s');
        $model->model_id = $model_id;
        $model->status = 0;
        $model->type = $type;
        $model->text = $text;
        $model->save();
    }

    // 处理已发送
    public static function consume($id)
    {
        $model = self::findOne(['id' => $id]);
        if ($model) {
            // $model->delete();
            $model->status = 1;
            $model->save();
        }
    }
}